Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/addoninfo.cpp: When loading a JSON addon, test 'script' key. #5797

Merged
merged 1 commit into from
Dec 25, 2023

Conversation

mvds00
Copy link
Contributor

@mvds00 mvds00 commented Dec 22, 2023

In case a user accidentally uses a wrong JSON file (e.g. naming.json, which is the config file for namingng.py), the code could give a confusing exception. This happens when the key 'script' is not defined as a string.

This is solved by testing the key for existence and type. In case 'script' is not a key or refers to a type other than a string, a clear error is given, stating for example: 'Loading naming.json failed. script must be set to a string value.'

The message is kept in line with other messages. Maybe it can be clarified further, e.g. 'Loading naming.json failed. A key "script" must be set with a string value referring to a Python script.' - in which case the errors relating to other keys may also be clarified.

@firewave
Copy link
Collaborator

Thanks for your contribution.

Please add a unit test for this. This applies to all PRs in general (at least in my book).

Unfortunately I am currently not able to follow up on things and I am not able to tell when that will be the case again. So if somebody else merges them there might quite some feedback from me way after this has been accepted.

FYI I had this change locally with a general refactoring of the JSON reading but I hadn't completed as tests yet and wasn't too happy with some of the code.

… of script key.

In case a user accidentally uses a wrong JSON file (e.g. naming.json, which is
the config file for namingng.py), the code could give a confusing exception.
This happens when the key 'script' is not defined as a string.

This is solved by testing the key for existence and type. In case 'script' is
not a key or refers to a type other than a string, a clear error is given,
stating for example: 'Loading naming.json failed. script must be set to a
string value.'

A unit test is included for this specific error.
@mvds00
Copy link
Contributor Author

mvds00 commented Dec 25, 2023

Please add a unit test for this. This applies to all PRs in general (at least in my book).

done.

@firewave firewave merged commit 403e7f1 into danmar:main Dec 25, 2023
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants